﻿// png_animation.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#define SDL_MAIN_HANDLED
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "SDL/SDL_log.h"
//#include <SDL/SDL_ttf.h>
#include <iostream>
#include "PlaneGame.hpp"
#include "Hero.h"
#include "BarButton.h"

#define HERO_IMG "/Users/yzy/Desktop/cpp/sdl2-learning-record/cpp_sdl2_plane/asset/walk.png"
#define BUTTON_IMG "/Users/yzy/Desktop/cpp/sdl2-learning-record/cpp_sdl2_plane/asset/myPlane.png"

int main(int argc, char *argv[])
{
    PlaneGame p;
	p.init();
	const char *heroImg = HERO_IMG;
	Sprite *hero = new Hero(heroImg, 0, 0);
	p.addChild(hero);

	Sprite *hero2 = new Hero(heroImg, 100, 0);
	p.addChild(hero2);

	CBrButton brBtn;
	SDL_Rect rc;
	rc.x = 50;
	rc.y = 50;
	rc.w = 50;
	rc.h = 50;
	brBtn.SetRect(rc);
	//为了设置render，进来第一件事就是设置render!!!!
	p.addChild(&brBtn);

	SDL_Surface *pSurfaceIn = IMG_LoadPNG_RW(SDL_RWFromFile(BUTTON_IMG, "rb"));
	SDL_Surface *pSurfaceOut = IMG_LoadPNG_RW(SDL_RWFromFile(BUTTON_IMG, "rb"));
	SDL_Surface *pSurfacePre = IMG_LoadPNG_RW(SDL_RWFromFile(BUTTON_IMG, "rb"));

	brBtn.CreateTexture(pSurfaceIn, pSurfaceOut, pSurfacePre);
	SDL_FreeSurface(pSurfaceIn);
	SDL_FreeSurface(pSurfaceOut);
	SDL_FreeSurface(pSurfacePre);

	//设置左键单击回调函数（如果需要响应左键单击）
	// brBtn.setFuncPressed(func_BRClick);
	// 5、在消息循环中响应消息
	// brBtn.handleEvent(sdl_event);

	p.mainLoop();
	return 0;
}